import React, { Component } from 'react'

export default class Detail extends Component {
  state = {
    num: 0
  }
  render() {
    console.log('this.props.location', this.props.location)
    let item = this.props.location.state.item;

    return (
      <div>
        详情  {item.name}
        <button onClick={() => {
          this.setState({ num: item.num-- })
        }}>-</button> {this.state.num}<button onClick={() => {
          this.setState({ num: item.num++ })
        }}>+</button>

        <button onClick={() => {
          this.props.history.push('/page/cart', { item })
        }}>加入购物车</button>
      </div>
    )
  }
}

